package com.longrise.android.byjk.plugins.vip.myintegral;

import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.R;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by callxkj on 2017/4/17.
 * 我的积分
 */

public class MyIntegralRcvAdapter extends MyIntegralQuickAdapter<EntityBean, BaseViewHolder> {

    private final String mCurrentPage; //当前是什么页面的rcvadapter  全部,支出,收入
    private List<EntityBean> mListBeans = new ArrayList<>();

    public MyIntegralRcvAdapter(String page) {
        super(R.layout.item_rcv_myintegral, null);
        this.mCurrentPage = page;
    }

    public void setDatas(EntityBean[] beans, boolean isLoadmore) {
        if(isLoadmore){
            mListBeans = new ArrayList<>();
        }else{
            mListBeans.clear();
        }
        if (beans != null) {
            for (int x = 0; x < beans.length; x++) {
                EntityBean bean = beans[x];
                mListBeans.add(bean);
            }
        }
        if(isLoadmore){
            addData(mListBeans);
        }else{
            setNewData(mListBeans);
        }
    }

    @Override
    protected void convert(BaseViewHolder helper, EntityBean bean) {
        String taskname = bean.getString("taskname");
        String updatetime = bean.getString("updatetime");
        helper.setText(R.id.item_rcv_myintegral_name_tv, taskname);
        helper.setText(R.id.item_rcv_myintegral_time_tv, updatetime);
        String score = bean.getString("score");
        switch (mCurrentPage) {
            case MyIntegralFragment.PAGE_ALL:
                String state = bean.getString("state");
                if ("1".equals(state)) {//获取积分
                    helper.setText(R.id.item_rcv_myintegral_tv_right, "+" + score);
                } else if ("0".equals(state)) { //消费积分
                    helper.setText(R.id.item_rcv_myintegral_tv_right, score);
                }
                break;
            case MyIntegralFragment.PAGE_EXPEND:
                helper.setText(R.id.item_rcv_myintegral_tv_right, score);
                break;
            case MyIntegralFragment.PAGE_INCOME:
                helper.setText(R.id.item_rcv_myintegral_tv_right, "+" + score);
                break;
        }
    }

}
